package com.zhugang.week10;

/**
 * @program algorithms
 * @description: change
 * @author: chanzhugang
 * @create: 2022/08/29 16:53
 */
public class Change {

    /**
     * 518 零钱兑换II
     *
     * @param amout
     * @param coins
     * @return
     */
    public int change(int amout, int[] coins) {
        // 凑成总金额的组合数
        // 计数问题：填满背包有多少种方法
        int n = coins.length;
        // 定义状态
        int[][] dp = new int[n][amout + 1];
        for (int c = 0; c <= amout / coins[0]; c++) {
            // 初始化第一行
            dp[0][c * coins[0]] = 1;
        }

        for (int i = 1; i < n; i++) {
            for (int j = 0; j <= amout; j++) {
                // 第i阶段可以用多少个硬币
                int k = j / coins[i];
                for (int c = 0; c <= k; c++) {
                    // 转移方程
                    dp[i][j] += dp[i - 1][j - c * coins[i]];
                }
            }
        }
        return dp[n - 1][amout];
    }
}